<include file="Public/popHeader"/>
<body class="hold-transition skin-blue sidebar-mini">
<!-- 内容页 -->
<div class="">
    <!-- 内容 -->
    <section class="content">
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-header">
                        <h3 class="box-title"></h3>
                        <div class="form-inline pull-right">
                            <form action="" method="get">
                                <fieldset>
                                    <div class="input-group input-group-sm">
                                        <span class="input-group-addon"><strong>货品名称</strong></span>
                                        <input type="text" class="form-control" placeholder="货品名称" name="name" value="" >
                                    </div>

                                    <div class="input-group input-group-sm">
                                        <div class="input-group-btn">
                                            <button type="submit" class="btn btn-primary"><i class="fa fa-search"></i>
                                            </button>
                                        </div>
                                    </div>

                                </fieldset>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover">
                            <tbody>
                            <tr>
                                <th><input type="checkbox" class="grid-select-all"></th>
                                <th>ID</th>
                                <th>货品名称</th>
                                <th>图片</th>
                                <th>促销状态</th>
                                <th>货品描述</th>
                                <th>市场价</th>
                                <th>销售价</th>
                                <th>库存</th>
                                <th>折后价</th>
                                <th>冻结库存</th>
                            </tr>
                            <foreach name="product_relation_msg" item="v">
                                <?php $satus = store_goods($v['store_pid'], $v['local_id']);?>
                                <tr class="cg-product-tr"
                                <?php if (checkProductIsGroupPromotion($v['store_pid'], $v['local_id']) || goods_is_Goods_promotion($v['store_pid'], $v['local_id']) || goods_is_shangou($v['store_pid'], $v['local_id'])){
                                            echo "style='text-decoration:line-through'";
                                        }
                                        ?>
                                >

                                <td>
                                    <input type="checkbox"
                                    <?php if (checkProductIsGroupPromotion($v['store_pid'], $v['local_id']) || goods_is_Goods_promotion($v['store_pid'], $v['local_id']) || goods_is_shangou($v['store_pid'], $v['local_id'])){
                                            echo "disabled='disabled'";
                                        } else {
                                            echo ' class="grid-item"';
                                        }
                                        ?>
                                    name="test" data-id="{$v.store_pid}"data-marketprice="{$v.marketprice}" data-price="{$v.price}" data-info="{$v.spec_info}" data-name="{$v.name}">
                                </td>
                                <td>{$v.store_pid}</td>
                                <td>{$v.name}</td>
                                <td><img class="scale-img" src="{:getThumb($v['goods_id'])}" data-bimg="{:getThumb($v['goods_id'])}"/></td>
                                <td>
                                    <?php
                                            if (goods_is_Order_promotion($v['store_pid'], $v['local_id'])) {
                                                echo '<span class="badge bg-green">订单促销</span>';
                                    }
                                    if (goods_is_Goods_promotion($v['store_pid'], $v['local_id'])) {
                                    echo '<span class="badge bg-green">商品促销</span>';
                                    }
                                    if (goods_is_shangou($v['store_pid'], $v['local_id'])) {
                                    echo '<span class="badge bg-green">闪购</span>';
                                    }

                                    if (checkProductIsGroupPromotion($v['store_pid'], $v['local_id'])) {
                                    echo '<span class="badge bg-green">组合促销</span>';
                                    }
                                    if (checkProductIsSpecial($v['store_pid'], $v['local_id'])) {
                                    echo '<span class="badge bg-green">专题商品包</span>';
                                    }
                                    ?>
                                </td>
                                <td>{$v.spec_info}</td>
                                <td>{$v.marketprice}</td>
                                <td>{$v.price}</td>
                                <td>{$v.store}</td>
                                <td>{$v.discount}</td>
                                <td>{$v.freez}</td>
                                </tr>
                            </foreach>
                            </tbody>
                        </table>
                    </div>
                    <div class="box-footer clearfix">
                        <input type="checkbox" class="grid-select-all">&nbsp;&nbsp;&nbsp;
                        <a class="btn btn-sm btn-info add-goods">保存</a>
                        {$show}
                    </div>
                    <!-- /.box-body -->
                </div>
            </div>
        </div>

    </section>
</div>
</body>
<script>
    $(function () {

        var chids = parent.$("#yc-goods-ids").val();
        var ychser = new YcChoser();
        ychser.setChosenIds(chids);

        $(".grid-item").each(function(){
            if(ychser.isRepeat($(this).attr("data-id"))){
                $(this).prop("checked", "checked");
            }
        });

        $('.grid-select-all').change(function () {
            if (this.checked) {
                $('.grid-item').prop("checked", true);
            } else {
                $('.grid-item').prop("checked", false);
            }
        });

        var index = parent.layer.getFrameIndex(window.name); //获取窗口索引

        $('.add-goods').on('click', function () {
            var supplier_id_data = [];
            $('input[name="test"]:checked').each(function(i){
                supplier_id_data[i] =$(this).data('price');
            });

            console.log(supplier_id_data);
            for ($j=0;$j<supplier_id_data.length;$j++){
                if (supplier_id_data[$j]<=0.01){
                    alert('商品小于等于0.01的不能促销');
                    return;
                }
            }
            var value=parent.$(".result-select")[0].value;
            var _display = "none";
            if(value==1){
                _display="inline-block"
            }
            $('.grid-item').each(function () {
                var id = $(this).data('id'); // id
                var name = $(this).data('name'); // 商品名称
                var info = $(this).data('info'); // 商品规格
                var price = $(this).data('price'); // 商品售价

                var flag = ychser.isRepeat($(this).attr("data-id"));
                if(flag && !$(this).is(':checked')){
                    ychser.remove();
                    parent.$('.ui-sortable').children("li").eq(ychser.getPosition()).remove();
                }else if ($(this).is(':checked') && !flag) {
                    ychser.add($(this).attr("data-id"));
                    var html = '';
                    html += '<li>';
                    html += '<input type="hidden" name="goods_id[]" value="'+id+'">';
                    html += '<a href="javascript:;" title="'+(name + info)+'" class="text ebatch-name" style="width:300px;"> '+name+'</a>';
                    html += '<h style="margin-right:50px">售价: '+price+'元 </h>';
                    html += '<h class="result_price_one"  style="color:red; display: '+ _display +';" >促销价:<input type="text"  style="width:60px;color:black" prices="'+price+'" class="is_price" name="promotion_price[]" value="">元</h>';
                    html += '<input type="hidden"  name="current_price[]" value="'+price+'"/>';
                    html += '<div class="tools">';
                    html += '<i class="fa fa-trash-o icondel" data-id="'+id+'" onclick="delGoodsItem(this)"></i>';
                    html += '</div>';
                    html += '</li>';
                    parent.$('.ui-sortable').append(html);


                }
            });
            parent.updateGoodsIds(ychser.getChosenIds());
            parent.layer.close(index);
            //parent.(".result-select")[0].selectedIndex;

        });
    });

    showBigPicture();
</script>

